<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>网络电子书城</title>
<link rel="stylesheet" href="css/main.css" type="text/css">
<script type="text/javascript">
	function changeNum(id,num,totalCount){
		num = parseInt(num);
		totalCount =parseInt(totalCount);
		
		if(num<1){
			if(confirm("是否确认要删除此商品？")){
				num = 0;
			}else{
				num=1;
			}
		}
		
		if(num>totalCount){
			alert("购买数量不能大于库存数量！");
			num=totalCount;
		}
		location.href="${pageContext.request.contextPath}/ChangeNumberServlet.do?id="+id+"&num="+num;
	}
</script>
</head>
<body class="main">
			 <%
			 request.setCharacterEncoding("utf-8");
			 request.getCharacterEncoding();
			 response.setCharacterEncoding("utf-8");
			 response.getCharacterEncoding();	 
			 response.setContentType("text/html;charset=utf-8");
				%>

	<jsp:include page="head.jsp" />

	<jsp:include page="menu_search.jsp" />

	<div id="divpagecontent">
		<table width="100%" border="0" cellspacing="0">
			<tr>
			<td><div style="text-align:right; margin:5px 10px 5px 0px">
						<a href="index.html">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;购物车
					</div>

					<table cellspacing="0" class="infocontent">
						<tr>
				<td><img alt="" src="ad/page_ad.jpg" width="666" height="89">
					<table width="100%" border="0" cellspacing="0">
						<tr>
							<td><img alt="" src="images/buy1.gif" width="635"
								height="38">
								</td>
						</tr>
						<tr>
							<td>
								<table cellspacing="1" class="carttable">
									<tr>
										<td width="10%">序号</td>
										<td width="30%">商品名称</td>
										<td width="10%">价格</td>
										<td width="20%">数量</td>
										<td width="10%">库存</td>
										<td width="10%">小计</td>
										<td width="10%">取消</td>
									</tr>
								</table>
								<c:forEach items="${cart }" var="entry" varStatus="vs">
								<table width="100%" border="0" cellspacing="0">
									<tr>
										<td width="10%">${entry.key.id }</td>
										<td width="30%">${entry.key.name }</td>
										<td width="10%">${entry.key.price }</td>
										<td width="20%">
										<input type="button" value="-" style="width: 20px" onclick="changeNum('${entry.key.id}','${entry.value-1 }','${entry.key.pnum }')"> 
										<input name="text" type="text" value="${entry.value }" style="width: 20px; text-align: center"> 
										<input type="button" value="+" style="width: 20px" onclick="changeNum('${entry.key.id}','${entry.value+1 }','${entry.key.pnum }')">
										</td>
										<td width="10%">${entry.key.pnum }</td>
										<td width="10%">${entry.value*entry.key.price }</td>
										<td width="10%"><a href="${pageContext.request.contextPath}/ChangeNumberServlet.do?id=${entry.key.id}&num=0"
											style="color: #FF0000; font-weight: bold">X</a></td>
									</tr>
								</table>
								<c:set var="sum" value="${sum+entry.value*entry.key.price }"> </c:set>
								</c:forEach>
								<table cellspacing="1" class="carttable">
									<tr>
										<td style="text-align: right; padding-right: 40px;"><font
											style="color: #FF6600; font-weight: bold">合计:&nbsp;&nbsp;${sum}元</font>
										</td>
									</tr>

								</table>
								<div style="text-align: right; margin-top: 10px">
									<a href="product_list.jsp"><img alt=""
										src="images/gwc_jx.gif" border="0"></a>
									&nbsp;&nbsp;&nbsp;&nbsp; 
									<a href="${pageContext.request.contextPath}/order.jsp"><img alt=""
										src="images/gwc_buy.gif" border="0"> </a>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</div>

<div></div>


</body>
</html>